#include <iostream>
#include <cstdio>
#define N 135
using namespace std;
typedef long long ll;

ll n, cnt, mn = 1e9, a[N], d[N][N], e[N][N];
int main()
{
    ll i, j, k, t;
    cin >> n;
    for (i = 0; i < n; i++)
    {
        scanf("%I64d", &t);
        if (t)
        {
            a[cnt++] = t;
            if (cnt > 128)
                break;
        }
    }
    if (i < n)
    {
        puts("3");
        return 0;
    }
    for (i = 0; i < cnt; i++)
        for (j = 0; j < cnt; j++)
        {
            if (i != j && a[i] & a[j])
                d[i][j] = e[i][j] = 1;
            else
                d[i][j] = e[i][j] = 1e9;
        }
    for (k = 0; k < cnt; k++)
    {

        for (i = 0; i < cnt; i++)
        {
            for (j = 0; j < cnt; j++)
            {
                mn = min(mn, e[i][k] + e[k][j] + d[i][j]);
            }
        }

        for (i = 0; i < cnt; i++)
        {
            for (j = 0; j < cnt; j++)
            {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    cout << (mn < 1e9 ? mn : -1);
    return 0;
}
